package com.example.jinyu.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

public class JsonUtils {
    private final Map<String, String> map = new HashMap<String, String>();

    public void add(String key, String value) {
        map.put(key, value);
    }

    public void add(String key, int value) {
        map.put(key, String.valueOf(value));
    }

    public void add(String key, long value) {
        map.put(key, String.valueOf(value));
    }

    public String getJson() {
        JSONObject jo = new JSONObject();

        Iterator<String> iterator = map.keySet().iterator();

        while (iterator.hasNext()) {
            String key = iterator.next();
            try {
                jo.put(key, map.get(key));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return jo.toString();
    }

}
